﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:converters="clr-namespace:myManga_App.Converters"
    xmlns:button="clr-namespace:myManga_App.Resources.Theme.Buttons"
    xmlns:objects="clr-namespace:myMangaSiteExtension.Objects;assembly=myMangaSiteExtension"
    xmlns:utils="clr-namespace:myMangaSiteExtension.Utilities;assembly=myMangaSiteExtension">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/myManga;component/Themes/CoreResourceDictionary.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    <converters:LoadImageFromMangaArchive x:Key="LoadImageFromMangaArchive"/>
    <converters:LoadImageFromChapterArchive x:Key="LoadImageFromChapterArchive"/>
    <converters:ObjectIsLocal x:Key="ObjectIsLocal"/>
    <converters:EqualsConverter x:Key="EqualsConverter"/>

    <converters:StringListToCSV x:Key="StringListToCSV"/>
    <converters:LocationListToCSV x:Key="LocationListToCSV"/>

    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="BorderBrush" Value="{DynamicResource window-theme-primary}"/>
        <Setter Property="BorderThickness" Value="3"/>
        <Setter Property="Foreground" Value="{DynamicResource window-foreground}"/>
        <Setter Property="Background" Value="{DynamicResource window-background}"/>
        <Setter Property="TextElement.Foreground" Value="{DynamicResource text-dark}"/>
        <Setter Property="MinHeight" Value="32"/>
        <Setter Property="Padding" Value="5,0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid>
                            <ContentPresenter
                                x:Name="Content"
                                Margin="{TemplateBinding Padding}"
                                Content="{TemplateBinding Content}"
                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <Grid x:Name="TRCornerTick" HorizontalAlignment="Right" VerticalAlignment="Top" Visibility="Collapsed">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Rectangle Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
                                <Rectangle Height="{Binding ActualWidth, Mode=OneWay, RelativeSource={RelativeSource Self}}" Grid.Row="1" Grid.Column="1"/>
                                <Rectangle 
                                Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}" 
                                Grid.RowSpan="2" 
                                Grid.ColumnSpan="2">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="1,0">
                                            <GradientStop Color="{DynamicResource window-theme-primary-color}" Offset="0.5"/>
                                            <GradientStop Offset="0.5"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock
                                    Text="{DynamicResource oi-check}"
                                    FontFamily="{DynamicResource OpenIconic}" 
                                    FontSize="14" 
                                    Foreground="{DynamicResource window-background}" 
                                    Grid.Column="1"
                                    Margin="-1,0,0,-1"/>
                            </Grid>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                            <Setter TargetName="TRCornerTick" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="HomeView_List_MangaListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Image
                                x:Name="CoverImage"
                                Grid.Column="0" 
                                Grid.RowSpan="4" 
                                Margin="6,2" 
                                Width="48" 
                                Height="72"
                                Source="{Binding MangaObject, Converter={StaticResource LoadImageFromMangaArchive}, FallbackValue=/myManga;component/Resources/Images/FallbackMangaIcon.png}"/>
                            <TextBlock Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" Foreground="{StaticResource text-dark}" FontWeight="Bold" FontSize="14" TextTrimming="CharacterEllipsis" Text="{Binding MangaObject.Name, FallbackValue=No-Name}"/>
                            <TextBlock Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Foreground="{StaticResource text-muted}" TextTrimming="CharacterEllipsis" Text="{Binding MangaObject.Locations, Converter={StaticResource LocationListToCSV}, Mode=OneWay, FallbackValue=No-Location}"/>
                            <TextBlock Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Foreground="{StaticResource text-muted}" TextTrimming="CharacterEllipsis" Text="{Binding MangaObject.DatabaseLocations, Converter={StaticResource LocationListToCSV}, Mode=OneWay, FallbackValue=No-Database}"/>
                            <TextBlock Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" Foreground="{StaticResource text-muted}" TextTrimming="CharacterEllipsis" Text="{Binding MangaObject.Genres, Converter={StaticResource StringListToCSV}, Mode=OneWay, FallbackValue=No-Genre}"/>

                            <TextBlock
                                x:Name="HasMoreToRead"
                                Visibility="Collapsed"
                                Grid.Column="0"
                                Grid.Row="0"
                                FontFamily="{DynamicResource OpenIconic}"
                                FontSize="20"
                                Text="{DynamicResource oi-badge}">
                                <TextBlock.Effect>
                                    <DropShadowEffect Color="{DynamicResource window-background-color}" ShadowDepth="0"/>
                                </TextBlock.Effect>
                            </TextBlock>
                        </Grid>
                        <Border.InputBindings>
                            <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding Path=DataContext.ResumeReadingCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
                        </Border.InputBindings>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                        <DataTrigger Binding="{Binding HasMoreToRead}" Value="True">
                            <Setter TargetName="HasMoreToRead" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="HomeView_Grid_MangaListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}"
                        ToolTip="{Binding MangaObject.Name, FallbackValue=No-Name}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <Image
                                x:Name="CoverImage"
                                Grid.Column="0" 
                                Grid.RowSpan="4"
                                Width="150"
                                Height="225"
                                Stretch="UniformToFill"
                                Source="{Binding MangaObject, Converter={StaticResource LoadImageFromMangaArchive}, FallbackValue=/myManga;component/Resources/Images/FallbackMangaIcon.png}" ClipToBounds="True"/>
                            <Border
                                Background="{DynamicResource window-background}"
                                VerticalAlignment="Bottom"
                                Width="{Binding ElementName=Content, Path=ActualWidth, Mode=OneWay}"
                                Height="{Binding ElementName=Title, Path=ActualHeight, Mode=OneWay}"
                                MaxHeight="50"
                                Opacity="0.9">
                                <TextBlock 
                                    x:Name="Title"
                                    Foreground="{StaticResource text-dark}" 
                                    FontWeight="Bold" 
                                    FontSize="14" 
                                    TextTrimming="CharacterEllipsis"
                                    TextWrapping="Wrap"
                                    TextAlignment="Center"
                                    Text="{Binding MangaObject.Name, FallbackValue=No-Name}"/>
                            </Border>
                            <Path
                                x:Name="IconBackground"
                                Visibility="Collapsed"
                                Grid.Column="0"
                                Grid.Row="0"
                                Data="M 0,0 v 48 L 48,0 Z"
                                StrokeThickness="1"
                                Opacity="0.9"
                                Fill="{DynamicResource window-theme-primary}"
                                Stroke="{DynamicResource window-theme-secondary}"
                                SnapsToDevicePixels="True"/>
                            <TextBlock
                                x:Name="HasMoreToRead"
                                Visibility="Collapsed"
                                Grid.Column="0"
                                Grid.Row="0"
                                FontFamily="{DynamicResource OpenIconic}"
                                FontSize="20"
                                Text="{DynamicResource oi-badge}"
                                Margin="8,4,0,0"
                                SnapsToDevicePixels="True">
                                <TextBlock.Effect>
                                    <DropShadowEffect Color="{DynamicResource window-background-color}" ShadowDepth="0"/>
                                </TextBlock.Effect>
                            </TextBlock>
                        </Grid>
                        <Border.InputBindings>
                            <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding Path=DataContext.ResumeReadingCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
                        </Border.InputBindings>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                            <Setter TargetName="IconBackground" Property="Fill" Value="{DynamicResource window-theme-secondary}"/>
                        </Trigger>
                        <DataTrigger Binding="{Binding HasMoreToRead}" Value="True">
                            <Setter TargetName="IconBackground" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="HasMoreToRead" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="HomeView_Grid_MangaListBoxItem_2">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <ControlTemplate.Resources>
                        <converters:BooleanInverter x:Key="BooleanInverter"/>
                    </ControlTemplate.Resources>
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}"
                        MinHeight="32"
                        MaxHeight="400"
                        MinWidth="32"
                        MaxWidth="400"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        ToolTip="{Binding MangaObject.Name}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <Image 
                                x:Name="CoverImage"
                                Source="{Binding MangaObject, Converter={StaticResource LoadImageFromMangaArchive}, FallbackValue=/myManga;component/Resources/Images/FallbackMangaIcon.png}"/>

                            <button:MetroButton
                                x:Name="ResumeReadingButton"
                                VerticalAlignment="Bottom"
                                Opacity="0"
                                Visibility="Collapsed"
                                Width="{Binding ActualWidth, Mode=OneWay, ElementName=CoverImage}"
                                FontFamily="{DynamicResource OpenIconic}"
                                Content="{DynamicResource oi-bookmark}"
                                ContentStringFormat="{}{0} Resume"
                                FontSize="18"
                                Padding="5"
                                Command="{Binding Path=DataContext.ResumeReadingCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>

                            <TextBlock
                                FontSize="18"
                                Padding="2,0"
                                Text="{Binding MangaObject.Name, FallbackValue=No-Name}"
                                Background="{DynamicResource window-theme-secondary}"
                                VerticalAlignment="Top"
                                Width="{Binding ActualWidth, Mode=OneWay, ElementName=CoverImage}"
                                TextTrimming="CharacterEllipsis"
                                TextWrapping="NoWrap"
                                TextAlignment="Center"/>

                            <TextBlock
                                x:Name="HasMoreToRead"
                                Visibility="Collapsed"
                                Grid.Column="0"
                                Grid.Row="0"
                                FontFamily="{DynamicResource OpenIconic}"
                                FontSize="28"
                                Text="{DynamicResource oi-badge}">
                                <TextBlock.Effect>
                                    <DropShadowEffect Color="{DynamicResource window-background-color}" ShadowDepth="0"/>
                                </TextBlock.Effect>
                            </TextBlock>
                        </Grid>
                        <Border.InputBindings>
                            <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding Path=DataContext.ResumeReadingCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
                        </Border.InputBindings>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation 
                                            Storyboard.TargetName="ResumeReadingButton"
                                            Storyboard.TargetProperty="Opacity"
                                            To="0.75" Duration="0:0:0.5" BeginTime="0:0:0.01"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ResumeReadingButton" Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation 
                                            Storyboard.TargetName="ResumeReadingButton"
                                            Storyboard.TargetProperty="Opacity"
                                            To="0" Duration="0:0:0.5" BeginTime="0:0:0"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ResumeReadingButton" Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.51" Value="{x:Static Visibility.Collapsed}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                        <DataTrigger Binding="{Binding HasMoreToRead}" Value="True">
                            <Setter TargetName="HasMoreToRead" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="SearchView_List_MangaListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Image
                                Grid.Column="0" 
                                Grid.RowSpan="4" 
                                Margin="6,2" 
                                Width="48" 
                                Height="72"
                                Source="{Binding Converter={StaticResource LoadImageFromMangaArchive}, FallbackValue=/myManga;component/Resources/Images/FallbackMangaIcon.png}"/>
                            <TextBlock Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" Foreground="{DynamicResource text-dark}" FontWeight="Bold" FontSize="14" TextTrimming="CharacterEllipsis" Text="{Binding Name, FallbackValue=No-Name}"/>
                            <TextBlock Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis" Text="{Binding Locations, Converter={StaticResource LocationListToCSV}, Mode=OneWay, FallbackValue=No-Location}"/>
                            <TextBlock Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis" Text="{Binding DatabaseLocations, Converter={StaticResource LocationListToCSV}, Mode=OneWay, FallbackValue=No-Database}"/>
                            <TextBlock Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis" Text="{Binding Genres, Converter={StaticResource StringListToCSV}, Mode=OneWay, FallbackValue=No-Genre}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="HomeView_List_ChapterListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock 
                                Grid.Row="0" 
                                VerticalAlignment="Center" 
                                Foreground="{DynamicResource text-dark}" 
                                FontWeight="Bold" FontSize="14" 
                                TextTrimming="CharacterEllipsis" 
                                Text="{Binding Name}"/>
                            <TextBlock 
                                Grid.Row="1" 
                                VerticalAlignment="Center" 
                                Foreground="{DynamicResource text-muted}" 
                                TextTrimming="CharacterEllipsis">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="Vol {0} Chap {1}.{2}">
                                        <Binding Path="Volume"/>
                                        <Binding Path="Chapter"/>
                                        <Binding Path="SubChapter"/>
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                            <!--<TextBlock
                                x:Name="LocationIcon"
                                Grid.Row="0"
                                Grid.Column="1"
                                FontFamily="{DynamicResource FontAwesome}"
                                Text="{StaticResource fa-cloud}"
                                TextAlignment="Center"
                                VerticalAlignment="Center"/>-->
                            <!--<button:MetroButton
                                x:Name="ReadChapterButton"
                                Grid.Row="0"
                                Grid.Column="1"
                                FontFamily="{DynamicResource OpenIconic}"
                                Content="{StaticResource oi-book}"
                                Command="{Binding Path=DataContext.ReadChapterCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
                                CommandParameter="{Binding}"/>
                            <button:MetroButton
                                x:Name="DownloadButton"
                                Grid.Row="1"
                                Grid.Column="1"
                                FontFamily="{DynamicResource OpenIconic}"
                                Content="{StaticResource oi-data-transfer-download}"
                                Command="{Binding Path=DataContext.DownloadChapterCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
                                CommandParameter="{Binding}"/>-->
                            <button:MetroButton
                                x:Name="ChapterActionButton"
                                Margin="0,2"
                                Grid.RowSpan="2"
                                Grid.Column="1"
                                Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
                                FontFamily="{DynamicResource OpenIconic}"
                                Content="{StaticResource oi-book}"
                                Command="{Binding Path=DataContext.ReadChapterCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl, AncestorLevel=2}}"
                                CommandParameter="{Binding}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ChapterActionButton" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                        <DataTrigger Value="True">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource EqualsConverter}">
                                    <Binding/>
                                    <Binding Path="DataContext.ResumeChapterObject" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}"/>
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <DataTrigger.Setters>
                                <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"/>
                                <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                                <Setter TargetName="ItemBorder" Property="BorderBrush" Value="{DynamicResource window-theme-primary-disabled}"/>
                                <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                            </DataTrigger.Setters>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Read}" Value="True">

                        </DataTrigger>
                        <DataTrigger Value="False">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource ObjectIsLocal}">
                                    <Binding/>
                                    <Binding Path="DataContext.MangaObject" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}"/>
                                    <Binding Path="DataContext.LastUpdate" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}"/>
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <Setter TargetName="ChapterActionButton" Property="Content" Value="{StaticResource oi-cloud-download}"/>
                            <Setter TargetName="ChapterActionButton" Property="Command" Value="{Binding Path=DataContext.DownloadChapterCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl, AncestorLevel=2}}"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="SearchView_ChapterListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Row="0" VerticalAlignment="Center" Foreground="{DynamicResource text-dark}" FontWeight="Bold" FontSize="14" TextTrimming="CharacterEllipsis" Text="{Binding Name}"/>
                            <TextBlock Grid.Row="1" VerticalAlignment="Center" Foreground="{DynamicResource text-muted}" TextTrimming="CharacterEllipsis">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="Vol {0} Chap {1}.{2}">
                                        <Binding Path="Volume"/>
                                        <Binding Path="Chapter"/>
                                        <Binding Path="SubChapter"/>
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                            <TextBlock
                                x:Name="LocationIcon"
                                Grid.Row="0"
                                Grid.Column="1"
                                FontFamily="{DynamicResource FontAwesome}"
                                Text="{StaticResource fa-cloud}"
                                TextAlignment="Center"
                                VerticalAlignment="Center"/>
                            <button:MetroButton
                                x:Name="DownloadButton"
                                Grid.Row="1"
                                Grid.Column="1"
                                FontFamily="{DynamicResource FontAwesome}"
                                Content="{StaticResource fa-download}"
                                Command="{Binding Path=DataContext.DownloadChapterCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
                                CommandParameter="{Binding}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="DownloadButton" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                        <DataTrigger Binding="{Binding Read}" Value="True">

                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsLocalContent}" Value="True">
                            <Setter TargetName="LocationIcon" Property="Text" Value="{StaticResource fa-hdd-o}"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="ReaderView_PageListBoxItem">
        <Setter Property="Foreground" Value="{DynamicResource window-theme-primary-disabled}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <Image MaxHeight="200" MaxWidth="200" 
                                   RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased">
                                <Image.Source>
                                    <MultiBinding Converter="{StaticResource LoadImageFromChapterArchive}" ConverterParameter="200">
                                        <Binding Path="DataContext.MangaObject">
                                            <Binding.RelativeSource>
                                                <RelativeSource Mode="FindAncestor" AncestorType="UserControl"/>
                                            </Binding.RelativeSource>
                                        </Binding>
                                        <Binding Path="DataContext.ChapterObject">
                                            <Binding.RelativeSource>
                                                <RelativeSource Mode="FindAncestor" AncestorType="UserControl"/>
                                            </Binding.RelativeSource>
                                        </Binding>
                                        <Binding/>
                                    </MultiBinding>
                                </Image.Source>
                            </Image>
                            <TextBlock 
                                VerticalAlignment="Bottom" 
                                Text="{Binding PageNumber}" 
                                FontSize="20"
                                Padding="3"
                                TextAlignment="Center" 
                                Background="#BF000000"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="SettingsView_SiteExtensionInformationObjectListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <ControlTemplate.Resources>
                        <converters:CommandParameterStringFormat x:Key="CommandParameterStringFormat"/>
                    </ControlTemplate.Resources>
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <StackPanel Orientation="Horizontal">
                                <button:MetroToggleButton 
                                    x:Name="EnabledButton"
                                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
                                    Content="{DynamicResource oi-x}"
                                    FontFamily="{DynamicResource OpenIconic}"
                                    IsChecked="{Binding Enabled, Mode=TwoWay}"/>
                                <TextBlock Text="{Binding Name}" FontSize="16" VerticalAlignment="Center" Margin="5,0,0,0"/>
                            </StackPanel>
                            <!-- Start -->
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                <button:MetroButton
                                    x:Name="UpArrow"
                                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
									FontFamily="{DynamicResource OpenIconic}" 
									Content="{DynamicResource oi-arrow-thick-top}"
									Command="{Binding DataContext.MoveUpCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
									CommandParameter="{Binding Name, ConverterParameter=Site:\{0\}, Converter={StaticResource CommandParameterStringFormat}}"/>
                                <button:MetroButton
                                    x:Name="DownArrow"
                                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
									FontFamily="{DynamicResource OpenIconic}" 
									Content="{DynamicResource oi-arrow-thick-bottom}"
									Command="{Binding DataContext.MoveDownCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
									CommandParameter="{Binding Name, ConverterParameter=Site:\{0\}, Converter={StaticResource CommandParameterStringFormat}}"/>
                            </StackPanel>
                            <!-- End -->
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Enabled}" Value="True">
                            <Setter TargetName="EnabledButton" Property="Content" Value="{DynamicResource oi-check}"/>
                        </DataTrigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="EnabledButton" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="UpArrow" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="DownArrow" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}" x:Key="SettingsView_DatabaseExtensionInformationObjectListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <ControlTemplate.Resources>
                        <converters:CommandParameterStringFormat x:Key="CommandParameterStringFormat"/>
                    </ControlTemplate.Resources>
                    <Border
                        x:Name="ItemBorder"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0"
                        Padding="{TemplateBinding BorderThickness}"
                        Background="{TemplateBinding Background}"
                        TextElement.Foreground="{TemplateBinding Foreground}">
                        <Grid
                            x:Name="Content"
                            Margin="{TemplateBinding Padding}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            TextBlock.TextAlignment="Left">
                            <StackPanel Orientation="Horizontal">
                                <button:MetroToggleButton 
                                    x:Name="EnabledButton"
                                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
                                    Content="{DynamicResource oi-x}"
                                    FontFamily="{DynamicResource OpenIconic}"
                                    IsChecked="{Binding Enabled, Mode=TwoWay}"/>
                                <TextBlock Text="{Binding Name}" FontSize="16" VerticalAlignment="Center" Margin="5,0,0,0"/>
                            </StackPanel>
                            <!-- Start -->
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                <button:MetroButton
                                    x:Name="UpArrow"
                                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
									FontFamily="{DynamicResource OpenIconic}" 
									Content="{DynamicResource oi-arrow-thick-top}"
									Command="{Binding DataContext.MoveUpCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
									CommandParameter="{Binding Name, ConverterParameter=Database:\{0\}, Converter={StaticResource CommandParameterStringFormat}}"/>
                                <button:MetroButton
                                    x:Name="DownArrow"
                                    Width="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
									FontFamily="{DynamicResource OpenIconic}" 
									Content="{DynamicResource oi-arrow-thick-bottom}"
									Command="{Binding DataContext.MoveDownCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
									CommandParameter="{Binding Name, ConverterParameter=Database:\{0\}, Converter={StaticResource CommandParameterStringFormat}}"/>
                            </StackPanel>
                            <!-- End -->
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding Enabled}" Value="True">
                            <Setter TargetName="EnabledButton" Property="Content" Value="{DynamicResource oi-check}"/>
                        </DataTrigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ItemBorder" Property="BorderThickness" Value="{Binding Path=BorderThickness, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
                            <Setter TargetName="ItemBorder" Property="Padding" Value="0"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="EnabledButton" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="UpArrow" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="DownArrow" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource window-theme-secondary}"/>
                            <Setter TargetName="ItemBorder" Property="TextElement.Foreground" Value="{DynamicResource window-theme-primary}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>